<template>
	<view>
		<view v-for="item,index in myArticle" :key="index">
			<list-card :item="item"></list-card>
		</view>
		
		<uni-load-more :status="load.loading" iconType="snow" />
	</view>
</template>

<script>
	import {get_my_article} from '@/common/api/user.js'
	export default {
		data() {
			return {
				// 我的文章
				myArticle: [],
				// 加载状态
				load: {
					loading: 'noMore',
					page: 1
				}
			}
		},
		onLoad() {
			this.getMyArticle()
		},
		// 触底事件
		onReachBottom() {
			console.log(1)
			if (this.load.loading === 'more') {
				this.load.page ++
			}
		},
		methods: {
			getMyArticle() {
				this.load.loading = 'loading'
				get_my_article({
					pageSize: 10,
					page: this.load.page
				})
				.then(res => {
					console.log('我的文章', res)
					this.load.loading = 'more'
					
					const oldData = this.myArticle || []
					const newData = res.data
					oldData.push(...newData)
					this.myArticle = oldData
					
					// 判断是否有数据
					if(res.data.length < 10) {
						return this.load.loading = 'noMore'
					}
					
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
